package com.zhuss.meeting.processor;

import com.zhuss.bean.bo.meeting.room.CreateRoomBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.meeting.db.dao.ext.MeetingRoomDao;
import com.zhuss.meeting.db.entity.MeetingRoom;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 创建用户 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("roomCreate")
public class RoomCreate extends AbstractProcessor<Object, CreateRoomBo> implements Processor<Object, CreateRoomBo> {

	@Autowired
	private MeetingRoomDao roomDao;

	@Override
	public Object process(CreateRoomBo createRoomBo) throws WpsException {
		MeetingRoom meetingRoom = new MeetingRoom();
		meetingRoom.setName(createRoomBo.getName());
		meetingRoom.setLocation(createRoomBo.getLocation());
		meetingRoom.setCapacity(createRoomBo.getCapacity());
		meetingRoom.setDemand(createRoomBo.getDemand());
		meetingRoom.setOther(createRoomBo.getOther());
		meetingRoom.setCharges(createRoomBo.getCharges());
		meetingRoom.setStatus(createRoomBo.getStatus());
		meetingRoom.setArea(createRoomBo.getArea());

		meetingRoom.setCreatorId(createRoomBo.getConcurrentUserId());
		meetingRoom.setCreator(createRoomBo.getConcurrentUserName());
		meetingRoom.setCreateTime(new Date());
		roomDao.create(meetingRoom);

		return null;
	}

	@Override
	public Object log(CreateRoomBo param) throws WpsException {
		OpLog record = new OpLog();
		record.setMoudle(MoudleEnum.会务.key());
		record.setAction(LogActionEnum.会议室创建.key());
		record.setTargetId(param.getTargetId());
		record.setTargetName(param.getName());
		record.setContent("参数: " + JsonUtil.toJson(param));
		record.setReason(param.getExceptionReason());

		record.setCreatorId(param.getConcurrentUserId());
		record.setCreator(param.getConcurrentUserName());
		record.setCreateTime(new Date());
		log(record);
		return null;
	}

	@Override
	public void check(CreateRoomBo createRoomBo) throws WpsException {

	}
}
